﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XSTDZ.ERP.Core.Generator;
using XSTDZ.ERP.Core.Extentions;


namespace XSTDZ.ERP.Domain.Models
{
    /// <summary>
    /// 损溢报告
    /// </summary>
    public partial class ProfitAndLossBill
    {
        public ProfitAndLossBill()
        {
            this.ProfitAndLossBillDetail = new HashSet<ProfitAndLossBillDetail>();
        }

        public ProfitAndLossBill InitProfitAndLossBill()
        {
            if (this.Id == null || this.Id.Equals(Guid.Empty))
            {
                this.Id = (Guid)new SequentialIdentityGenerator().Next;
            }
            this.CreateTime = DateTime.Now;
            this.Deleted = 0;
           
            return this;
        }
        public ProfitAndLossBill AddDetails(IEnumerable<ProfitAndLossBillDetail> details)
        {
            details.Each(d => AddDetails(d));
            return this;
        }
        public ProfitAndLossBill AddDetails(ProfitAndLossBillDetail detail)
        {
            if (!this.ProfitAndLossBillDetail.Contains(detail))
            {
                if (detail.ProfitAndLossBillID == null || detail.ProfitAndLossBillID.Equals(Guid.Empty))
                {
                    detail.ProfitAndLossBillID = this.Id;
                }
                this.ProfitAndLossBillDetail.Add(detail.InitProfitAndLossBillDetail());
            }
            return this;
        }
    }
}
